'''
角色管理页面测试
'''
from Lib.base.page_object.role_manager.role_manager import RoleManager
from selenium.webdriver.common.by import By
import allure
import os
from Lib.common.assert_class import AssertClass
import pytest


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestRoleManager.roleManager = RoleManager(login)
    TestRoleManager.assert_class = AssertClass(login)


@allure.feature('角色管理页面测试')
class TestRoleManager:

    @allure.title('新建角色')
    def test_1_create_role(self):
        '''
        新增角色
        :return:
        '''
        self.roleManager.create_role()
        # 设置断言
        assert_arg = (By.XPATH, '//p[text()="新建角色成功"]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='新建角色成功', context='新建角色')

    @allure.title('查看角色列表')
    def test_2_role_list(self):
        '''
        查看角色列表
        :return:
        '''
        self.roleManager.role_list()
        # 设置断言
        assert_arg1 = (By.XPATH, '//tbody/tr[1]/td[3]//span')
        assert_arg2 = (By.XPATH, '//tbody/tr[2]/td[3]//span')
        self.assert_class.make_assert_by_compare_time(args1=assert_arg1, args2=assert_arg2, context="角色列表")

    @allure.title('查看角色详情和编辑角色')
    def test_3_detail_and_update_role(self):
        '''
        查看角色详情和编辑角色
        :return:
        '''
        self.roleManager.role_detail_and_update()
        # 设置断言
        assert_arg = (By.XPATH, '//p[text()="编辑角色成功"]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='编辑角色成功', context='查看详情和编辑角色')

    @allure.title('启用和删除角色')
    def test_4_open_and_delete(self):
        '''
        启用和删除角色
        :return:
        '''
        self.roleManager.role_open_and_delete()
        # 设置断言
        assert_arg = (By.XPATH, '//p[text()="删除角色成功"]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='删除角色成功', context='启用和删除角色')


if __name__ == '__main__':
    pytest.main(['-v', './car_test.py', './role_manager_test.py'])
    # pytest.main(['-v', './role_manager_test.py', '--alluredir', '../result', '--clean-alluredir'])
    # os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    # os.system('allure generate  ../result -o ../report/ --clean')
